package client

import (
	"encoding/json"
	"github.com/idoubi/goz"
)

func Get(url string, params map[string]interface{}, Headers map[string]interface{}) map[string]interface{} {
	cli := goz.NewClient()

	resp, err := cli.Get(url, goz.Options{
		Query:   params,
		Headers: Headers,
	})
	if err != nil {
		panic(err)
	}

	body, err := resp.GetBody()
	if err != nil {
		panic(err)
	}

	var res map[string]interface{}
	_ = json.Unmarshal(body, &res)
	return res
}

func Post(url string, paramsP map[string]interface{}, Headers map[string]interface{}) interface{} {
	cli := goz.NewClient()

	resp, err := cli.Post(url, goz.Options{
		Headers: Headers,
		FormParams: paramsP,
	})
	if err != nil {
		panic(err)
	}

	body, err := resp.GetBody()
	if err != nil {
		panic(err)
	}

	contents := body.GetContents()

	return contents
}
